package top.haijunit.work.configurer;

import io.swagger.v3.oas.models.ExternalDocumentation;
import io.swagger.v3.oas.models.OpenAPI;
import io.swagger.v3.oas.models.info.Contact;
import io.swagger.v3.oas.models.info.Info;
import io.swagger.v3.oas.models.info.License;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.HashMap;

/**
 * knife4j 接口文档配置
 *
 * @author zhanghaijun
 * @since 2024-08-14
 */
@Configuration
public class OpenApiConfigurer {

    @Bean
    public OpenAPI customOpenAPI() {
        // 作者名称
        Contact contact = new Contact().name("zhanghaijun")
            .email("zhanghaijun_java@163.com")
            .url("https://haijunit.top")
            .extensions(new HashMap<>());
        // 授权名称
        License license = new License().name("Apache 2.0")
            .url("https://www.apache.org/licenses/LICENSE-2.0.html")
            .identifier("Apache-2.0")
            .extensions(new HashMap<>());
        // Api接口文档标题
        Info info = new Info().title("SpringBoot相关的测试示例文档")
            .description("SpringBoot相关的测试示例文档描述")
            .version("1.0.0")
            .license(license)
            .contact(contact);
        ExternalDocumentation documentation = new ExternalDocumentation()
            .description("OpenApi 3 & Spring Boot")
            .url("https://springdoc.org");
        return new OpenAPI().info(info).externalDocs(documentation);
    }
}
